import socketio
server = 'https://7hangzhou.goeasy.io/socket.io/?EIO=3&transport=polling&j=0&t=NgPMy4u&b64=1'


def create_client():
    sio = socketio.Client()

    @sio.event
    def connect():
        print('connection established')
        sio.emit('client', {'foo': 'bar'})

    @sio.on('serve')
    def on_message(data):
        print('client received a message!', data)
    # @sio.event
    # def message(data):
    #     print('message received with ', data)
    #     sio.emit('client', {'response': 'my response'})

    @sio.event
    def connect_error(data):
        print("The connection failed!")
        sio.disconnect()

    @sio.event
    def disconnect():
        print('disconnected from server')
        sio.disconnect()

    sio.connect(server)
    sio.wait()


create_client()
